#include "graphicalmf.h"

GraphicalMF::GraphicalMF(const QString &type, const int &size):
        BasicMembershipFunction(type, size)
{
}

void GraphicalMF::paint(QPainter *painter,  const double &xShift,
                        const double &xScale,  const double &yShift,
                        const double &yScale) const
{
    const double RADIUS = 5;

    QScopedArrayPointer<QPointF> p(this->getGraphicsPoints(xShift,
                                                           xScale,
                                                           yShift,
                                                           yScale));

    for(int i = 0; i < this->m_size - 1; ++i)
        painter->drawLine(p[i], p[i+1]);

    for(int i = 0; i < this->m_size; ++i)
        painter->drawEllipse(p[i].x() - RADIUS/2, p[i].y() - RADIUS/2,
                             RADIUS, RADIUS);
}

QPointF *GraphicalMF::getGraphicsPoints(const double &xShift,
                                        const double &xScale,
                                        const double &yShift,
                                        const double &yScale) const
{
    QPointF *points = new QPointF[m_size];

    for(int i = 0; i < m_size; ++i)
        points[i] = QPointF(xShift + xScale * m_points[i].x(),
                            yShift + yScale * m_points[i].y());

    return points;
}
